package com.kyxx.mycommonproject.dianpu;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.kyxx.mycommonproject.R;
import com.kyxx.mycommonproject.base.LazyFragment;
import com.kyxx.mycommonproject.dianpu.RecyclerViewAdapter;
import com.kyxx.mycommonproject.widget.GridViewForScrollView;
import com.kyxx.mycommonproject.widget.ListViewForScrollView;

public class ShopAllGoodsFragment extends LazyFragment {
    // 标志位，标志已经初始化完成。
    private String key;
    private TextView tv;
    private boolean isPrepared;
    private RecyclerView rv_good;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_shop_all_goods, container, false);
        tv = (TextView) view.findViewById(R.id.tv);
        rv_good = (RecyclerView) view.findViewById(R.id.rv);
        rv_good.addItemDecoration(new DividerGridItemDecoration(getActivity()));
        isPrepared = true;
        lazyLoad();
        return view;
    }

    @Override
    protected void lazyLoad() {
        if (!isPrepared || !isVisible) {
            return;
        }
        tv.setText(key);
        rv_good.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        rv_good.setAdapter(new GridViewAdapter(getActivity()));
    }

    public void setKey(String key) {
        this.key = key;
    }

}
